﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CodeBuilder
{
    public partial class FormResult : Form
    {
        string result = string.Empty;
        string lastFileFolder = string.Empty;
        string tableName = string.Empty;
        public FormResult(string result)
        {
            InitializeComponent();
            this.result = result;
        }
        public FormResult(string result, string lastFileFolder, string tableName)
        {
            InitializeComponent();
            this.result = result;
            this.lastFileFolder = lastFileFolder;
            this.tableName = tableName;
        }

        private void FormResult_Load(object sender, EventArgs e)
        {
            textBox.Text = result;
        }
        private void textBox_DoubleClick(object sender, EventArgs e)
        {

            if (string.IsNullOrEmpty(tableName))
                return;
            //获取指定路径
            if (!string.IsNullOrEmpty(lastFileFolder))
            {
                folderBrowserDialog.SelectedPath = lastFileFolder;
            }
            folderBrowserDialog.Description = "请选择要导出的路径";
            folderBrowserDialog.ShowDialog();
            if (!string.IsNullOrEmpty(folderBrowserDialog.SelectedPath))
            {
                System.IO.File.WriteAllText(Path.Combine(folderBrowserDialog.SelectedPath, tableName + ".cs"), result);
                MessageBox.Show("OK");
            }
        }
    }
}
